package com.bianguo.android.tencentpushdemo.tasks;

import android.os.AsyncTask;

import com.bianguo.android.tencentpushdemo.entity.Weather;
import com.bianguo.android.tencentpushdemo.utils.MyLog;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
 * Created by Administrator on 2017/7/11.
 */

public class WeatherTask extends AsyncTask<String, Void, Weather> {

    @Override
    protected Weather doInBackground(String... params) {
        Weather weather = null;
        if (params != null) {
            String weatherUrl = params[0];
            MyLog.myLog("weatherUrl = " + weatherUrl);
            try {
                Document document = Jsoup.connect(weatherUrl).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31").timeout(5000).get();
                Elements select = document.select("div.header");
                MyLog.myLog("select = " + select.toString() + ", select = " + select.text());
                Elements select1 = select.select("div.top_weather");
                MyLog.myLog("select1 = " + select1.toString());
                Elements elements = select1.select("div.weather");
                MyLog.myLog("weather = " + elements.text());
                Elements a = elements.select("a");
                MyLog.myLog("a = " + a.text());
            } catch (IOException e) {
                MyLog.myLog("loadWeatherTask error:" + e.getMessage());
                e.printStackTrace();
            }
        }
        return weather;
    }
}
